import os,sys
import subprocess

# 根据 files_list.txt
# 生成程序下载脚本 download.bat

print(os.path.dirname(os.path.realpath(sys.executable)))

#src_str  = input("工作目录:")
src_str =  os.path.dirname(os.path.realpath(sys.executable))
com_name = input("串口名字:")

f  = open( src_str+'/files_list.txt', 'r' )
f2 = open( src_str+'/download.bat', 'w' )
lines = f.readlines()

for name in lines:
    f2.write("ampy -p "+ com_name +" put "+name)
f.close()
f2.close()


# #下载文件
# p = subprocess.Popen("cmd.exe /c" + src_str+'/download.bat', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# curline = p.stdout.readline()
# while(curline != b''):
#     print(curline)
#     curline = p.stdout.readline()
# p.wait()

